package cn.lrwjz.androidguide.ui.exmple.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import cn.lrwjz.androidguide.R;
import cn.lrwjz.androidguide.adapter.PostAdapter;
import cn.lrwjz.androidguide.model.Post;

public class HomeFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);

        // 设置RecyclerView
        RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));

        // 创建测试数据
        List<Post> posts = new ArrayList<>();
        for (int i = 1; i <= 20; i++) {
            posts.add(new Post(i, "标题 " + i, "这是内容 " + i));
        }

        PostAdapter adapter = new PostAdapter(posts);
        recyclerView.setAdapter(adapter);

        // 设置NestedScrollView
        NestedScrollView scrollView = view.findViewById(R.id.nested_scroll_view);
        scrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) 
            (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
                // 可以在这里处理滚动事件
            });

        return view;
    }
} 